<%--
  Created by IntelliJ IDEA.
  User: jiang
  Date: 2021/7/20
  Time: 15:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Login Page</title>
    <!-- 样 式 文 件 -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/component/pear/css/pear.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/admin/css/other/login.css"/>
</head>
<!-- 代 码 结 构 -->
<body background="${pageContext.request.contextPath}/resources/admin/images/background.svg"
      style="background-size: cover;">
<form class="layui-form" action="javascript:void(0);">
    <div class="layui-form-item">
        <img id="codeImg" class="logo" src="${pageContext.request.contextPath}/resources/admin/images/logo.png"/>
        <div class="title">汽车租赁系统</div>
        <div class="desc">
        </div>
    </div>
    <div class="layui-form-item">
        <input placeholder="账 户 : admin " lay-verify="required" hover class="layui-input" name=username value="admin"/>
    </div>
    <div class="layui-form-item">
        <input type="password" placeholder="密 码 : 123456 " lay-verify="required" hover class="layui-input"
               name="password" value="123456"/>
    </div>
    <div class="layui-form-item">
        <input placeholder="验证码 : " hover lay-verify="required" class="code layui-input layui-input-inline"
               name="code"/>
        <img id="validateCodeImg" src="${pageContext.request.contextPath}/login/code.do" class="codeImage"/>
    </div>
    <div class="layui-form-item">
        <input type="checkbox" name="" title="记住密码" lay-skin="primary" checked>
    </div>
    <div class="layui-form-item">
        <button type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
            登 入
        </button>
    </div>
</form>
<!-- 资 源 引 入 -->
<script src="${pageContext.request.contextPath}/resources/component/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/resources/component/pear/pear.js"></script>
<script>
    layui.use(['form', 'button', 'popup', 'jquery', 'layer'], function () {
        var form = layui.form;
        var button = layui.button;
        var popup = layui.popup;
        var $ = layui.jquery;
        var layer = layui.layer;

        $("#validateCodeImg").click(function () {
            let newCodeUrl = $(this).attr("src") + "?" + new Date().getTime();
            $(this).attr("src", newCodeUrl);
        })

        // 登 录 提 交
        form.on('submit(login)', function (data) {
            // 访问登录的接口
            $.post("${pageContext.request.contextPath}/login/doLogin.do", data.field, function (res) {
                if (res.code != 200) {
                    layer.msg(res.msg);
                    return false;
                }
                /// 登录
                button.load({
                    elem: '.login',
                    time: 1000,
                    done: function () {
                        popup.success("登录成功", function () {
                            location.href = "${pageContext.request.contextPath}/page/toMain.do"
                        });
                    }
                })
            });
            return false;

        });
    })
</script>
</body>
</html>